﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProcessManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProcessManagement.ProcessRouteItemVMs
{
    public partial class ProcessRouteItemListVM : BasePagedListVM<ProcessRouteItem_View, ProcessRouteItemSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProcessRouteItem_View>> InitGridHeader()
        {
            return new List<GridColumn<ProcessRouteItem_View>>{
                
                this.MakeGridHeader(x => x.ProcessRouteItem_Routie).SetTitle(@Localizer["Page.工艺路线"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_GroupCode).SetTitle(@Localizer["Page.工序组"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_OpCode).SetTitle(@Localizer["Page.工序编号"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_OpName).SetTitle(@Localizer["Page.工序名称"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_OpType).SetTitle(@Localizer["Page.工序类型"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_ErpOpCode).SetTitle(@Localizer["Page.工厂工序"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_StdOpDuration).SetTitle(@Localizer["Page.标准加工工时"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_StdPrepDuration).SetTitle(@Localizer["Page.标准准备工时"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_PolicyCheckPrevProc).SetTitle(@Localizer["Page.校验上一工序动作"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_PolicyCheckProcBom).SetTitle(@Localizer["Page.校验生产BOM动作"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_PolicyCheckProcess).SetTitle(@Localizer["Page.工艺校验策略"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_CtlAttr).SetTitle(@Localizer["Page.工艺管控属性"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_Pos).SetTitle(@Localizer["Page.工艺位置"].Value).SetSort(true),
                this.MakeGridHeader(x => x.ProcessRouteItem_Etag).SetTitle(@Localizer["Page.处理标记"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_EquipmentId).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_EquipmentCode).SetTitle(@Localizer["Page.设备编号"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProcessRouteItem_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProcessRouteItem_View> GetSearchQuery()
        {
            var query = DC.Set<ProcessRouteItem>()
                
                .CheckEqual(Searcher.RoutieId, x=>x.RoutieId)
                .CheckContain(Searcher.GroupCode, x=>x.GroupCode)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckContain(Searcher.OpName, x=>x.OpName)
                .CheckEqual(Searcher.OpType, x=>x.OpType)
                .CheckContain(Searcher.ErpOpCode, x=>x.ErpOpCode)
                .CheckEqual(Searcher.StdOpDuration, x=>x.StdOpDuration)
                .CheckEqual(Searcher.StdPrepDuration, x=>x.StdPrepDuration)
                .CheckEqual(Searcher.PolicyCheckPrevProc, x=>x.PolicyCheckPrevProc)
                .CheckEqual(Searcher.PolicyCheckProcBom, x=>x.PolicyCheckProcBom)
                .CheckEqual(Searcher.PolicyCheckProcess, x=>x.PolicyCheckProcess)
                .CheckEqual(Searcher.CtlAttr, x=>x.CtlAttr)
                .CheckEqual(Searcher.Pos, x=>x.Pos)
                .CheckContain(Searcher.Etag, x=>x.Etag)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckEqual(Searcher.EquipmentId, x=>x.EquipmentId)
                .CheckContain(Searcher.EquipmentCode, x=>x.EquipmentCode)
                .CheckContain(Searcher.Aux_1, x=>x.Aux_1)
                .CheckContain(Searcher.Aux_2, x=>x.Aux_2)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProcessRouteItem_View
                {
				    ID = x.ID,
                    
                    ProcessRouteItem_Routie = x.Routie.RoutingName,
                    ProcessRouteItem_GroupCode = x.GroupCode,
                    ProcessRouteItem_OpCode = x.OpCode,
                    ProcessRouteItem_OpName = x.OpName,
                    ProcessRouteItem_OpType = x.OpType,
                    ProcessRouteItem_ErpOpCode = x.ErpOpCode,
                    ProcessRouteItem_StdOpDuration = x.StdOpDuration,
                    ProcessRouteItem_StdPrepDuration = x.StdPrepDuration,
                    ProcessRouteItem_PolicyCheckPrevProc = x.PolicyCheckPrevProc,
                    ProcessRouteItem_PolicyCheckProcBom = x.PolicyCheckProcBom,
                    ProcessRouteItem_PolicyCheckProcess = x.PolicyCheckProcess,
                    ProcessRouteItem_CtlAttr = x.CtlAttr,
                    ProcessRouteItem_Pos = x.Pos,
                    ProcessRouteItem_Etag = x.Etag,
                    ProcessRouteItem_Active = x.Active,
                    ProcessRouteItem_EquipmentId = x.EquipmentId,
                    ProcessRouteItem_EquipmentCode = x.Equipment.EquipName,
                    ProcessRouteItem_CreateTime = x.CreateTime,
                    ProcessRouteItem_UpdateTime = x.UpdateTime,
                    ProcessRouteItem_CreateBy = x.CreateBy,
                    ProcessRouteItem_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProcessRouteItem_View: ProcessRouteItem
    {
        
        public string ProcessRouteItem_Routie { get; set; }
        public string ProcessRouteItem_GroupCode { get; set; }
        public string ProcessRouteItem_OpCode { get; set; }
        public string ProcessRouteItem_OpName { get; set; }
        public OpTypeEnum? ProcessRouteItem_OpType { get; set; }
        public string ProcessRouteItem_ErpOpCode { get; set; }
        public decimal? ProcessRouteItem_StdOpDuration { get; set; }
        public decimal? ProcessRouteItem_StdPrepDuration { get; set; }
        public PolicyCheckPrevProcEnum? ProcessRouteItem_PolicyCheckPrevProc { get; set; }
        public PolicyCheckProcBomEnum? ProcessRouteItem_PolicyCheckProcBom { get; set; }
        public PolicyCheckProcessEnum? ProcessRouteItem_PolicyCheckProcess { get; set; }
        public ProcCtlAttrEnum? ProcessRouteItem_CtlAttr { get; set; }
        public int? ProcessRouteItem_Pos { get; set; }
        public string ProcessRouteItem_Etag { get; set; }
        public bool? ProcessRouteItem_Active { get; set; }
        public long? ProcessRouteItem_EquipmentId { get; set; }
        public string ProcessRouteItem_EquipmentCode { get; set; }
        public DateTime? ProcessRouteItem_CreateTime { get; set; }
        public DateTime? ProcessRouteItem_UpdateTime { get; set; }
        public string ProcessRouteItem_CreateBy { get; set; }
        public string ProcessRouteItem_UpdateBy { get; set; }

    }

}